/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.colswedev.lab4.helpersViews;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.colswedev.lab4.entity.Rol;
import org.colswedev.lab4.service.RolService;

/**
 *
 * @author James
 */
public class ConvertidorRol implements Converter{

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
        //string es el id del rol
        if(string == null)
            return null;
        return RolService.getInstance().getRolById(Integer.parseInt(string));
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object o) {
        //o es el rol
        if(o == null)
            return null;
        return ((Rol) o).getId().toString();
    }

}
